Skip to content

Return empty modules array when module command is not available #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

vlradstake
Copy link
Contributor

When connecting to a Redis server with limited rights the module command may not be available. Predis throws an exception and executing commands is not possible. This happend with Redis Enterprise Cloud server where Redisearch is available but the module command not.

Copy link
Owner

@MacFJA MacFJA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For PHP-CS-Fixer errors, the command make fix-code can be run to auto-fix them

if (strpos($exception->getMessage(), 'unknown command') === false) {
throw $exception;
}
$modules = [];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can return null directly, because the foreach will have nothing to run

Suggested change
$modules = [];
return null;

try {
$modules = $client->executeRaw('module', 'list') ?? [];
} catch (\Throwable $exception) {
if (strpos($exception->getMessage(), 'unknown command') === false) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yoda style test is used (see PHP-CS-Fixer error: https://github.com/MacFJA/php-redisearch/runs/7054519075?check_suite_focus=true)

Suggested change
if (strpos($exception->getMessage(), 'unknown command') === false) {
if (false === strpos($exception->getMessage(), 'unknown command')) {

$modules = $client->executeRaw('module', 'list') ?? [];
try {
$modules = $client->executeRaw('module', 'list') ?? [];
} catch (\Throwable $exception) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MacFJA MacFJA mentioned this pull request Aug 5, 2022
@MacFJA
Copy link
Owner

MacFJA commented Aug 5, 2022

Closing in favor of #53

@MacFJA MacFJA closed this Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants